const getters = {
  isMobile: state => state.app.isMobile,
  theme: state => state.app.theme,
  color: state => state.app.color,
  token: state => state.user.token,
  avatar: state => state.user.avatar,
  nickname: state => state.user.name,
  welcome: state => state.user.welcome,
  userInfo: state => state.user.info,
  addRouters: state => state.permission.addRouters,
  sysMessageCount: state => state.user.sysMessageCount,
  sysMessageList: state => state.user.sysMessageList,
  multiTab: state => state.app.multiTab,
  // lang: state => state.i18n.lang,
  checkBtnPermissions: (state) => (roles) => {
    if (state.user.btnPermissions === undefined) {
      return false
    }
    try {
      const hasIn = state.user.btnPermissions.indexOf(roles)
      return hasIn > -1
    } catch (e) {
      return false
    }
  },
  getKeepAliveList: (state) => () => {
    return state.keepAliveList
  },
  getCloseMessageList: (state) => () => {
    return state.closeMessageList
  },
  checkKeepAliveTmpList: (state) => (component) => {
    let result = false
    state.catchArrTmp.map(x => {
      if (component === x) {
        result = true
      }
    })
    return result
  },
  getDepartmentName: (state) => (departCode) => {
    let departName = ''
    departCode = departCode + ''
    if (departCode.indexOf(',') > -1) {
      departCode.split(',').map(x => {
        const departInfo = state.user.departList.get(x)
        if (departInfo) {
          departName = departInfo.name + ',' + departName
        }
      })
    } else {
      const departInfo = state.user.departList.get(departCode)
      if (departInfo) {
        departName = departInfo.name + ',' + departName
      }
    }
    return departName.length > 0 ? departName.substring(0, departName.length - 1) : ''
  },
  // 获取部门最近的公司名称
  getDepartmentOrgName: (state) => (departCode) => {
    let departName = ''
    departCode = departCode + ''
    if (departCode.indexOf(',') > -1) {
      departCode.split(',').map(x => {
        const departInfo = state.user.departList.get(x)
        if (departInfo) {
          departName = departInfo.orgName + ',' + departName
        }
      })
    } else {
      const departInfo = state.user.departList.get(departCode)
      if (departInfo) {
        departName = departInfo.orgName + ',' + departName
      }
    }
    if (departName === 'undefined,') {
      return '-'
    } else {
      return departName.length > 0 ? departName.substring(0, departName.length - 1) : ''
    }
  },
  // 获取部门最近的公司departCode
  getDepartmentOrgDepartCode: (state) => (departCode) => {
    let orgCode = ''
    departCode = departCode + ''
    if (departCode.indexOf(',') > -1) {
      departCode.split(',').map(x => {
        const departInfo = state.user.departList.get(x)
        if (departInfo) {
          orgCode = departInfo.orgCode + ',' + orgCode
        }
      })
    } else {
      const departInfo = state.user.departList.get(departCode)
      if (departInfo) {
        orgCode = departInfo.orgCode + ',' + orgCode
      }
    }
    if (orgCode === 'undefined,') {
      return '-'
    } else {
      return orgCode.length > 0 ? orgCode.substring(0, orgCode.length - 1) : ''
    }
  },
  // 获取部门最近的项目名称
  getDepartmentProjectName: (state) => (departCode) => {
    let departName = ''
    departCode = departCode + ''
    if (departCode.indexOf(',') > -1) {
      departCode.split(',').map(x => {
        const departInfo = state.user.departList.get(x)
        if (departInfo) {
          departName = departInfo.projectName + ',' + departName
        }
      })
    } else {
      const departInfo = state.user.departList.get(departCode)
      if (departInfo) {
        departName = departInfo.projectName + ',' + departName
      }
    }
    if (departName === 'undefined,') {
      return '-'
    } else {
      return departName.length > 0 ? departName.substring(0, departName.length - 1) : ''
    }
  },
  // 获取角色名称
  getRoleName: (state) => (roleId) => {
    let roleName = ''
    roleId.split(',').map(x => {
      const roleInfo = state.user.roleList.get(x)
      if (roleInfo) {
        roleName = roleInfo.name + ',' + roleName
      }
    })
    return roleName.length > 0 ? roleName.substring(0, roleName.length - 1) : ''
  },
  // 获取岗位名称
  getPostionName: (state) => (postionId) => {
    const postionName = state.user.postionList.get(postionId)
    return postionName
  },
  sysDictListForType: (state) => (type) => {
    if (state.user.sysDictList[type]) {
      return state.user.sysDictList[type]
    }
  }
}

export default getters
